package com.ruoyi.project.personal.signature.controller;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.personal.signature.domain.UserSignature;
import com.ruoyi.project.personal.signature.service.IUserSignatureService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 个性签名Controller
 * 
 * @author wyh
 * @date 2024-06-16
 */
@RestController
@RequestMapping("/personal/signature/api")
public class UserSignatureApiController extends BaseController
{
    @Autowired
    private IUserSignatureService userSignatureService;

    /**
     * 查询个性签名列表
     */
    @PreAuthorize("@ss.hasPermi('personal:signature:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserSignature userSignature)
    {
        Long userId = SecurityUtils.getUserId();
        userSignature.setUserId(userId);

        userSignature.setStatus("已通过");

        startPage();
        List<UserSignature> list = userSignatureService.selectUserSignatureList(userSignature);
        return getDataTable(list);
    }

    /**
     * 获取个性签名详细信息
     */
    @PreAuthorize("@ss.hasPermi('personal:signature:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(userSignatureService.selectUserSignatureById(id));
    }

    /**
     * 新增个性签名
     */
    @PreAuthorize("@ss.hasPermi('personal:signature:add')")
    @Log(title = "个性签名", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserSignature userSignature)
    {
        //获取当前用户id
        Long userId = SecurityUtils.getUserId();
        userSignature.setUserId(userId);

        //空个性签名默认通过
        if(StringUtils.isBlank(userSignature.getSignature())){
            userSignature.setStatus("已通过");
        }

        userSignature.setStatus("待审核");
        return toAjax(userSignatureService.insertUserSignature(userSignature));
    }

}
